#pragma once
#include <string>
#include <stdint.h>

class TcpClient {
public:
    TcpClient() : m_clientfd(-1) {}
    ~TcpClient() { close(); }
    bool connect(const std::string& in_ip, const uint16_t in_port);
    bool send(const std::string& buffer);
    bool recv(std::string &buffer, const size_t maxLen);
    bool close();
private:
    int m_clientfd;
    std::string m_ip;
    uint16_t m_port;
};

class TcpServer {
public:
    TcpServer() : m_listenfd(-1), m_clientfd(-1) {}
    ~TcpServer() { closeListen(); closeClient(); }
    bool serverInit(const uint16_t in_port);
    bool accept();
    bool send(const std::string& buffer);
    bool recv(std::string& buffer, const size_t maxLen);
    const std::string& clientIp() const;
    bool closeListen();
    bool closeClient();
private:
    int m_listenfd, m_clientfd;
    std::string m_clientip;
    uint16_t m_port;
};